package cn.edu.cug.cs.gtl.docsrv.auth.service.imp;

import cn.edu.cug.cs.gtl.docsrv.auth.dao.ResourceDao;
import cn.edu.cug.cs.gtl.docsrv.auth.service.ResourceService;
import cn.edu.cug.cs.gtl.mybatis.mapper.auth.AuthResource;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    ResourceDao resourceDao;

    @Override
    public boolean insertResource(String authResourceJSON) {
        AuthResource authResource = JSON.parseObject(authResourceJSON, AuthResource.class);
        if(authResource!=null)
            return resourceDao.insertResource(authResource);
        else
            return false;
    }

    @Override
    public boolean updateResource(String authResourceJSON) {
        AuthResource authResource = JSON.parseObject(authResourceJSON, AuthResource.class);
        if(authResource!=null)
            return resourceDao.updateResource(authResource);
        else
            return false;
    }

    @Override
    public boolean deleteResource(String authResourceName) {
        return resourceDao.deleteResource(authResourceName);
    }

    @Override
    public String getResource(String authResourceName) {
        AuthResource authResource = resourceDao.getResource(authResourceName);
        return JSON.toJSONString(authResource);
    }
}
